package com.yyfax.ph.progress.detail;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.aspsine.irecyclerview.IViewHolder;
import com.yyfax.common.recyclerview.BaseRecycleAdapter;
import com.yyfax.ph.R;
import com.yyfax.ph.common.utils.Constants;

import java.util.List;

/**
 * Created by fan on 2017/12/5.
 * Copyright  2017 www.yylending.com. All Rights Reserved.
 */
public class HistoricalProgressAdapter extends BaseRecycleAdapter<ProgressDetailModel.History> {

	public HistoricalProgressAdapter(List<ProgressDetailModel.History> historys) {
		addData(historys);
	}

	@Override
	public IViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
		View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.historical_progress_item_layout, null);
		return new ViewHolder(view);
	}

	@Override
	public void onBindViewHolder(IViewHolder holder, int position) {
		ViewHolder viewHolder = (ViewHolder) holder;
		ProgressDetailModel.History history = getDataSet().get(position);
		if (position == getCount() - 1) {
			if(TextUtils.equals(Constants.PROGRESS_HISTORY_LAST_NODE_OVER,history.nodeType)) {
				viewHolder.mItemLine.setVisibility(View.GONE);
			}else {
				viewHolder.mItemLine.setVisibility(View.VISIBLE);
				viewHolder.mItemLine.setBackgroundResource(R.drawable.historical_progress_dotted_line);
			}
		} else {
			viewHolder.mItemLine.setVisibility(View.VISIBLE);
			viewHolder.mItemLine.setBackgroundResource(R.drawable.historical_progress_solid_line);
		}
		viewHolder.mDateTv.setText(history.updateDate);
		viewHolder.mStatusTv.setText(history.statusDesc);
	}

	@Override
	public int getItemCount() {
		return getCount();
	}

	class ViewHolder extends IViewHolder {
		@BindView(R.id.item_line)
		ImageView mItemLine;
		@BindView(R.id.status_tv)
		TextView mStatusTv;
		@BindView(R.id.date_tv)
		TextView mDateTv;

		ViewHolder(View view) {
			super(view);
			ButterKnife.bind(this, view);
		}
	}
}